Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distsql: tiny refactor to make the code more robust #10557

Merged
merged 3 commits into from
May 21, 2019

Conversation

tiancaiamao
Copy link
Contributor

What problem does this PR solve?

There is a potential goroutine leak found here:

goroutine 2190640781 [chan send, 217 minutes]:
github.com/pingcap/tidb/distsql.(*selectResult).fetch(0xc000c26d10, 0x2189000, 0xc0de519300)
/home/jenkins/workspace/build_tidb_release-3.0/go/src/github.com/pingcap/tidb/distsql/select_result.go:97 +0x2e8
created by github.com/pingcap/tidb/distsql.(*selectResult).Fetch
/home/jenkins/workspace/build_tidb_release-3.0/go/src/github.com/pingcap/tidb/distsql/select_result.go:84 +0x53

What is changed and how it works?

https://github.com/pingcap/tidb/compare/master...tiancaiamao:leak?expand=1#diff-7492d01b7aac81533194642850a45b8eL103

This line only listen for one exit condition.
If multiple error arrive and caller call Close, without calling selectResult.Next() any more,
nobody would drain from r.results so the fetch goroutine blocks sending here forever (leak).

I'm not quite sure that's the case, but this tiny refactor would make the code more robust.

Check List

Tests

  • No code

@tiancaiamao tiancaiamao added component/coprocessor type/enhancement The issue or PR belongs to an enhancement. and removed component/coprocessor labels May 21, 2019
@tiancaiamao
Copy link
Contributor Author

PTAL @lysu @jackysp

@tiancaiamao
Copy link
Contributor Author

/run-all-tests

@codecov
Copy link

codecov bot commented May 21, 2019

Codecov Report

Merging #10557 into master will decrease coverage by 0.0246%.
The diff coverage is 100%.

@@               Coverage Diff                @@
##             master     #10557        +/-   ##
================================================
- Coverage   77.3469%   77.3222%   -0.0247%     
================================================
  Files           413        413                
  Lines         87273      87275         +2     
================================================
- Hits          67503      67483        -20     
- Misses        14592      14605        +13     
- Partials       5178       5187         +9

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tiancaiamao tiancaiamao merged commit 9b62c5a into pingcap:master May 21, 2019
@tiancaiamao tiancaiamao deleted the leak branch May 21, 2019 10:17
db-storage pushed a commit to db-storage/tidb that referenced this pull request May 29, 2019
SunRunAway pushed a commit to SunRunAway/tidb that referenced this pull request Jun 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants